package gameOfLife;

import java.awt.Color;
import java.util.ArrayList;

import javax.swing.ImageIcon;

import interfaces.Cell;
import interfaces.World;
import lib.Location;
import lib.WorldFactory;
import lib.WorldUI;

public class GameOfLife {
	
	/**
	 * Runs the automata
	 */
	public static void main(String[] args){
		
		/* defines the first world */
		int dim = 5;
		boolean two_dim = true;
		World w = WorldFactory.getWorld(dim, two_dim);
		
		w.put(new AliveCell().getName(),new ImageDisplayEx(new ImageIcon("src/images/dan.jpg")));
		w.put(new DeadCell().getName(),new ImageDisplayEx(new ImageIcon("src/images/dan2.jpg")));
		
		for(int i = 0; i < dim; i++){
			for(int j = 0; j < dim; j++){
				Cell cell = ((i+j) % 2) == 0 ? 
						new AliveCell() :
						new DeadCell();				
				w.setCell(cell,new Location(i,j));
			}
		}		
		
		/* defines the second world, which is an instance of of the
		 * "small exploder" automaton found here: http://www.bitstorm.org/gameoflife/ */
		int dim2 = 19;
		World w2 = WorldFactory.getWorld(dim2,two_dim);
		
		w2.put(new AliveCell().getName(),new ColorDisplayEx(Color.red));
		w2.put(new DeadCell().getName(),new ColorDisplayEx(Color.black));
		ArrayList<Location> locs = new ArrayList<Location>();
		locs.add(new Location(7,8));
		locs.add(new Location(8,9));
		locs.add(new Location(8,8));
		locs.add(new Location(9,9));
		locs.add(new Location(6,9));
		locs.add(new Location(7,10));
		locs.add(new Location(8,10));;
		
		w2.setAllCells(new DeadCell());
		w2.setCellsFromArrayList(locs, new AliveCell());		
				
		/* world 3*/
		int dim3 = 10;
		World w3 = WorldFactory.getWorld(dim3, !two_dim);
		w3.put(new AliveCell().getName(),new ColorDisplayEx(Color.blue));
		w3.put(new DeadCell().getName(),new ColorDisplayEx(Color.green));
		
		for(int i = 0; i < dim3; i++){
			Cell cell = (i % 2) == 0 ? 
					new AliveCell() :
					new DeadCell();				
			w3.setCell(cell,new Location(i,0));		
		}
		
	
		ArrayList<World> worlds = new ArrayList<World>();
		worlds.add(w);
		worlds.add(w2);
		worlds.add(w3);
		WorldUI gui = new WorldUI(worlds, 1, 3);
	}
}
